package com.zxy.car.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zxy.car.entity.PayplanEntity;
import com.zxy.car.service.PayplanService;
import com.zxy.common.utils.PageUtils;
import com.zxy.common.utils.R;



/**
 * 
 *
 * @author zxy
 * @email 1695483548@qq.com
 * @date 2022-04-15 10:01:01
 */
@RestController
@RequestMapping("car/payplan")
public class PayplanController {
    @Autowired
    private PayplanService payplanService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = payplanService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		PayplanEntity payplan = payplanService.getById(id);

        return R.ok().put("payplan", payplan);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody PayplanEntity payplan){
		payplanService.save(payplan);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody PayplanEntity payplan){
		payplanService.updateById(payplan);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		payplanService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /*
     * 加入订单
     * */
    @RequestMapping("/addPlan/{id}")
    public R addRecord(@PathVariable("id")Integer id){
        payplanService.addPlan(id);
        return R.ok();
    }
    /*
    * 还款
    * */
    @RequestMapping("/backmoney/{id}")
    public R backmoney(@PathVariable("id")Integer id){
        payplanService.backmoney(id);
        return R.ok();
    }

    /*
     * 提前结清还款
     * */
    @RequestMapping("/backmoney5m/{id}")
    public R backmoney5m(@PathVariable("id")Integer id){
        payplanService.backmoney5m(id);
        return R.ok();
    }

}
